<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateSubscriptionRecordsTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('think_subscription_records', [
            'id' => 'id',
            'signed' => true,
            'auto_increment' => true
        ]);
        $table
            // Transaction identifiers
            ->addColumn('original_transaction_id', 'string', ['null' => false])
            ->addColumn('transaction_id', 'string', ['null' => true])
            ->addColumn('web_order_line_item_id', 'string', ['null' => true])
            ->addColumn('bundle_id', 'string', ['null' => true])
            ->addColumn('product_id', 'string', ['null' => true])
            ->addColumn('subscription_group_identifier', 'string', ['null' => true])
            ->addColumn('purchase_date', 'datetime', ['null' => true])
            ->addColumn('original_purchase_date', 'datetime', ['null' => true])
            ->addColumn('expires_date', 'datetime', ['null' => true])
            ->addColumn('signed_date', 'datetime', ['null' => true])
            ->addColumn('revocation_date', 'datetime', ['null' => true])
            ->addColumn('quantity', 'integer', ['null' => true])
            ->addColumn('type', 'string', ['null' => true])
            ->addColumn('app_account_id', 'string', ['null' => false])
            ->addColumn('in_app_ownership_type', 'string', ['null' => true])
            ->addColumn('revocation_reason', 'integer', ['null' => true])
            ->addColumn('is_upgraded', 'boolean', ['null' => true])
            ->addColumn('offer_type', 'integer', ['null' => true])
            ->addColumn('offer_identifier', 'string', ['null' => true])
            ->addColumn('offer_discount_type', 'string', ['null' => true])
            ->addColumn('offer_period', 'string', ['null' => true])
            ->addColumn('environment', 'string', ['null' => true])
            ->addColumn('storefront', 'string', ['null' => true])
            ->addColumn('storefront_id', 'string', ['null' => true])
            ->addColumn('transaction_reason', 'string', ['null' => true])
            ->addColumn('currency', 'string', ['null' => true])
            ->addColumn('price', 'biginteger', ['null' => true])
            ->addColumn('app_transaction_id', 'string', ['null' => true])
            ->addColumn('create_time', 'datetime', ['null' => false])
            ->addColumn('update_time', 'datetime', ['null' => false])
            ->create();
    }
}
